#!/bin/sh

# Slackware build script for eclipse 
# Written by core (eroc@linuxmail.org)

# This script is just a binary repackaging.

set -e

PRGNAM=eclipse
VERSION=3.3
ARCH=i586      # Leave this alone.
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar -xzvf $CWD/$PRGNAM-SDK-$VERSION-linux-gtk.tar.gz

# Binary directory is "eclipse" so rename it
mv $PRGNAM $PRGNAM-$VERSION
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# Move the binary directory to $PKG/opt
mkdir -p $PKG/opt
mv $TMP/$PRGNAM-$VERSION $PKG/opt
( cd $PKG/opt ; ln -s $PRGNAM-$VERSION $PRGNAM )

# Add a script to run eclipse in /usr/bin
mkdir -p $PKG/usr/bin
cat $CWD/eclipse > $PKG/usr/bin/eclipse
chmod 0755 $PKG/usr/bin/eclipse

# Add an icon for eclipse
mkdir -p $PKG/usr/share/pixmaps
( cd $PKG/usr/share/pixmaps ; ln -s /opt/$PRGNAM-$VERSION/icon.xpm eclipse.xpm )

# Add eclipse to KDE/GNOME/XFCE menu
mkdir -p $PKG/usr/share/applications
cat $CWD/eclipse.desktop > $PKG/usr/share/applications/eclipse.desktop

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cd $PKG/opt/$PRGNAM-$VERSION
cp -a epl-v10.html notice.html readme/readme_eclipse.html about.html \
  about_files $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n -p $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
